#!/bin/bash
# Convert Markdown presentation to PowerPoint (PPTX)
# Usage: ./md_to_pptx.sh <input.md> [output.pptx]

INPUT_FILE="$1"
OUTPUT_FILE="${2:-${INPUT_FILE%.md}.pptx}"

if [ -z "$INPUT_FILE" ]; then
    echo "Usage: $0 <input.md> [output.pptx]"
    echo "Example: $0 ../presentations/project-intro.MD project-intro.pptx"
    exit 1
fi

if [ ! -f "$INPUT_FILE" ]; then
    echo "Error: File '$INPUT_FILE' not found"
    exit 1
fi

echo "Converting $INPUT_FILE to $OUTPUT_FILE..."

# Convert using pandoc
# --slide-level=2 means use ## for slide breaks
# -t pptx specifies PowerPoint output format
pandoc "$INPUT_FILE" \
    -o "$OUTPUT_FILE" \
    -t pptx \
    --slide-level=2 \
    --reference-doc=/usr/share/pandoc/data/reference.pptx 2>/dev/null || \
pandoc "$INPUT_FILE" \
    -o "$OUTPUT_FILE" \
    -t pptx \
    --slide-level=2

if [ $? -eq 0 ]; then
    echo "✓ Successfully created: $OUTPUT_FILE"
else
    echo "✗ Conversion failed"
    exit 1
fi

